package com.ikun.core.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * web mvc 配置
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

//    @Value("${app.upload.dir:/opt/uploads}")
//    private String uploadDir;

    /**
     * 静态资源映射，将请求 /api/fetch/file/** 映射到项目根目录的/files/
     *
     * @param registry 资源处理器注册器
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 注意：末尾一点要带斜杠，表示该文件夹内
//        String saveDir = System.getProperty("user.dir") + File.separator + "files" + File.separator;
        registry.addResourceHandler("/" + GlobalConfig.publicPrefix + "/**")
                .addResourceLocations("file:" + GlobalConfig.fileSavePath);
    }
}
